/*
 * HTMLArbre.cpp
 *
 *  Created on: 19 mars 2012
 *      Author: lsinapayen
 */


#include "HTMLArbre.h"



void HTMLArbre::traiterBalises(vector<Item*> * liste, vector<Item*> * treatedList ){
	vector<Item*>::iterator itItem;

	itItem = liste->begin();
	while(itItem != liste->end()){
		Element * e = new Element((*itItem)->getName(),new string());
		cout<<(*itItem)->getName()<<endl;
		treatedList->push_back(e);
		//todo traitement différencié
	}

}

/*void HTMLArbre::pushItem(Item item){
}*/

void HTMLArbre::applyTemplate(string xmlName, XMLArbre xsl){
	vector<Item*>::iterator itItem;
	vector<Item*> * xslItems;
	vector<Item*> racineItems;
	vector<Item*> treatedItems;
	vector<Attribut*>::iterator itAtt;
	Element * e;
	//string nom;
	string nsp;

	xslItems = xsl.getRacine()->getItems();
	itItem = xslItems->begin();
//	nom = "";
	nsp = "";
	e = new Element(new string(),new string());

	while(itItem != xslItems->end()){
		e = dynamic_cast<Element*>(*itItem);
		if (e){
			itAtt = e->getAttributs()->begin();
			while(itAtt != e->getAttributs()->end()){
				if(strcmp((*itAtt)->getName()->c_str(),xmlName.c_str())==0){
					//TODO namespace ?
					ContentElement * ce = new ContentElement(&xmlName,&nsp);
					traiterBalises(e->getItems(),&treatedItems);
					ce->setItems(&treatedItems);
					racineItems.push_back(ce);
				}
			}

		}

		itItem++;
	}

}

HTMLArbre::HTMLArbre(XMLArbre xsl, XMLArbre xml) : XMLArbre() {
	string xmlName;
	vector<Item*>::iterator itItem;
	vector<Item*> * xmlItems;

	xmlItems = xml.getRacine()->getItems();
	itItem = xmlItems->begin();

	while(itItem != xmlItems->end()){
			applyTemplate(*(*itItem)->getName(), xsl);
			itItem++;
	}


}

HTMLArbre::~HTMLArbre() {
	// TODO Auto-generated destructor stub
}
